home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Key / KeyCom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  14.8 KB  |  724 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     keycom.c
  5.  
  6.     DESCRIPTION
  7.     command interface for keyboard-control with key functions
  8.  
  9.     NOTES
  10.     for interface with [X]DME version < 1.70
  11.         all functions in this module make use of av[] (readonly)
  12.     extensively uses keyhashes.c
  13.  
  14.     BUGS
  15.     plenty - but where
  16.  
  17.     TODO
  18.  
  19.  
  20.     EXAMPLES
  21.  
  22.     description of the user-commands:
  23.  
  24.     the commands below might get other names;
  25.     if so, please update their descriptions according
  26.     to the names they are used in command.c
  27.  
  28. *!***************************************************************************
  29. *!
  30. *!  KEYS:
  31. *!  ****
  32. *!
  33. *!  the following commands allow access to [X]DME's keymappings
  34. *!  that way it is possible for each user to create an individual
  35. *!  UI for "his" [X]DME, for "his" programming language and for
  36. *!  his wishes.
  37. *!
  38. *! >MAP   key command    (will be "MAP key command help")
  39. *! >UNMAP key
  40. *!
  41. *!    with these commands YOu can modify the keytable:
  42. *!    MAP adds or modifies an existing key-entry to the keytable
  43. *!    UNMAP deletes an existing key-entry
  44. *!
  45. *!    key consists of a set of QUALIFIERS, a "-" and one code-
  46. *!    specification (both case sensitive)
  47. *!    the qualifiers are:
  48. *!        s == any shift (caps-lock with alpha-keys)
  49. *!        c == control
  50. *!        a == any alt
  51. *!        A == any amiga
  52. *!        L == left mouse button
  53. *!        M == middle mouse button
  54. *!        R == right mouse button
  55. *!        u == key-up ( release of a key )
  56. *!        x == extended qualifier x
  57. *!        y == extended qualifier y
  58. *!        z == extended qualifier z
  59. *!        r == repeat
  60. *!
  61. *!    the code-specification is one out of:
  62. *!      main keyboard:
  63. *!        [single lowercase character] == the key on you main keyboard - that shows it
  64. *!        [single uppercase alpha]     == the key on .... but that means a set s-qualifier
  65. *!
  66. *!      numeric keypad:
  67. *!        nk0 .. nk9        == numerik keypad 0..9
  68. *!        nk+|nk-|nk*|nk/|nk. == numerik keypad +,-,*,/,.
  69. *!
  70. *!        there are two more key on yor numerik keypad
  71. *!        with american|british mapping they are used as nk( and nk)
  72. *!        with most european mappings they are used as nk[ and nk]
  73. *!        with canadian mapping they are used as nk@ and nk°
  74. *!        if there is a standart mapping, that does map these keys
  75. *!        in another way, they are NOT supported yet. (please mail)
  76. *!
  77. *!      other special keys:
  78. *!        f1 .. f10       == Function keys
  79. *!        hel        == help-key
  80. *!        esc        == escape
  81. *!        del        == delete
  82. *!        bac|bs       == backspace ( <- )
  83. *!        tab        == tabulator
  84. *!        ent        == enter
  85. *!        spc|spa       == spacebar
  86. *!        up|dow|rig|lef == cursor keys
  87. *!
  88. *!        lmb|mmb|rmb    == mouse buttons
  89. *!        mmo        == mouse movement with a mousebutton pressed
  90. *!        ?m2|?m3|?m4    == (? in {lmr}) double/triple/qraduple clicks of a
  91. *!                  certain mouse button (times out!)
  92. *!
  93. *!    note that as mousebuttons can act for qualifiing as well as for
  94. *!    specifiing, the specifiing mousebutton must also be qualifiing
  95. *!    e.g L-rmb should not work, but LR-rmb should
  96. *!
  97. *!    note that certain keys may be used as dead-keys;
  98. *!    keys that are deading when pressed without qualifiers
  99. *!    are not accessible with that keyboard-interface
  100. *!    e.g. on german keyboards there is a key "'" next to "\"
  101. *!         which cannot be accessed
  102. *!    on the other hand, if a key is deading on a qualified level,
  103. *!    but not when pressed without qualifiers, You can remap it
  104. *!    e.g on german keyboards alt-f is deading, but -f not, so
  105. *!        You can access a-f; and if You map a-f to any function,
  106. *!        It looses it deading function for [X]DME
  107. *!        EXAMPLE:  <alt-f> <a> creates something like "á"
  108. *!        after a "MAP a-f (NULL)" the same key-sequence
  109. *!        creates a normal "a"
  110. *!
  111. *!    note that map soon is to expect another parameter:
  112. *!        the help-string that contains information 'bout the command
  113. *!
  114. *!    keys with the x|y|z-qualifiers set can not accessed immediately
  115. *!    first You must set the right extended qualifiers (see QUALIFIER
  116. *!    command), then You may press the remaining qualifiers and keys
  117. *!    these keys were introduced to allow something like the
  118. *!    CTL-X prefix of MicroEmacs
  119. *!
  120. *!    ATN! we check only up to three characters for code-specifiction
  121. *!        so e.g. -space is recognized as -spa some people
  122. *!        call this a feature, but in fact it is a BUG, as that
  123. *!        method avoids rexx-commands which start whose 3 first digits
  124. *!        are the same like a special key from being implicitely executed
  125. *!
  126. *! >QUALIFIER qualifierset
  127. *!
  128. *!    that command allows setting of certain qualifiers
  129. *!    independently to the qualifiers pressed manually on the keyboard
  130. *!    (see above) it is designed to allow multi-key-sequences
  131. *!
  132. *!    EXAMPLE:
  133. *!         MAP  c-x (QUALIFIER x)
  134. *!         MAP cx-a (SAVEOLD)
  135. *!        would cause the sequence <ctrl-x> <ctrl-a> calling SAVEOLD
  136. *!
  137. *! >KEYSAVE filename
  138. *!
  139. *!    save the keytable as a file that can be
  140. *!    read by KEYLOAD
  141. *!
  142. *! >KEYLOAD filename
  143. *!
  144. *!    clear the keytable and instead build a new
  145. *!    contents out of the file filename
  146. *!
  147. *!
  148. *!  KEYTABLES:
  149. *!  *********
  150. *!
  151. *!  the following commands do only make sense, if
  152. *!  You are using multiple keytables
  153. *!  at [X]DME's start a keytable called "default" is created;
  154. *!  for "normal" usage, that single strip may suffer.
  155. *!
  156. *!  Please note that the above MENU... commands apply to the
  157. *!  CURRENT keytable (and only to it)
  158. *!
  159. *! >USEKEYTABLE name
  160. *!
  161. *!    search for a certain keytable and use it as the current one
  162. *!
  163. *! >REMKEYTABLE
  164. *!
  165. *!    delete the current keytable, if it is not the only one
  166. *!
  167. *! >NEWKEYTABLE name
  168. *!
  169. *!    if there is already a keytable called name,
  170. *!        simply call USEKEYTABLE name
  171. *!    else create a new keytable called name and use it
  172. *!
  173. *!
  174.  
  175.     SEE ALSO
  176.     keyhashes.c keycodes.c keyaddes.c keycontrol.c
  177.  
  178.     INDEX
  179.  
  180.     HISTORY
  181.     14-Dec-92  b_null created
  182.     16-Dec-92  b_null some names updated & introduced currenthash
  183.     05-08-94   null added STATIC Command Interface
  184.     24-09-94 b_null used std_-read/write-file
  185.     04-12-94 b_noll removed dead protos
  186.  
  187.     $Date: 1994/09/20 11:09:43 $ last update
  188.  
  189. ******************************************************************************/
  190.  
  191. /**************************************
  192.         Includes
  193. **************************************/
  194. /* we do not need anythig else - I think */
  195. #define  KEY_INTERNAL            /* PATCH_NULL < 24-06-94 */
  196. #include "defs.h"
  197. #ifdef PATCH_NULL
  198. #include "COM.h"
  199. #endif
  200.  
  201.  
  202. /**************************************
  203.         Globale Variable
  204. **************************************/
  205.  
  206.  
  207.  
  208. /**************************************
  209.       Interne Defines & Strukturen
  210. **************************************/
  211. /* nothing */
  212.  
  213. /**************************************
  214.         Interne Variable
  215. **************************************/
  216. /* nothing */
  217.  
  218. /**************************************
  219.        Interne Prototypes
  220. **************************************/
  221. /* nothing */
  222.  
  223. /*****************************************************************************
  224.  
  225.     NAME
  226.     do_map
  227.  
  228.     PARAMETER
  229.     void
  230.  
  231.     RESULT
  232.     -/-
  233.  
  234.     RETURN
  235.     void
  236.  
  237.     DESCRIPTION
  238.     command interface for keyhashes/mapkey
  239.  
  240.     NOTES
  241.     for interface with [X]DME version < 1.70
  242.  
  243.     BUGS
  244.  
  245.     EXAMPLES
  246.  
  247.     SEE ALSO
  248.     do_unmap keyhashes/mapkey
  249.  
  250.     INTERNALS
  251.  
  252.     HISTORY
  253.     14-Dec-92  b_null created
  254.  
  255. ******************************************************************************/
  256.  
  257. DEFUSERCMD("map", 2, CF_VWM|CF_ICO, void, do_map, (void),)
  258. {
  259.     mapkey ( currenthash(), GetArg(1), GetArg(2), NULL );
  260. } /* do_map */
  261.  
  262.  
  263.  
  264. /*****************************************************************************
  265.  
  266.     NAME
  267.     do_unmap
  268.  
  269.     PARAMETER
  270.     void
  271.  
  272.     RESULT
  273.     -/-
  274.  
  275.     RETURN
  276.     void
  277.  
  278.     DESCRIPTION
  279.     command interface for keyhashes/unmapkey
  280.  
  281.     NOTES
  282.     for interface with [X]DME version < 1.70
  283.  
  284.     BUGS
  285.  
  286.     EXAMPLES
  287.  
  288.     SEE ALSO
  289.     do_map, keyhashes/unmapkey
  290.  
  291.     INTERNALS
  292.  
  293.     HISTORY
  294.     14-Dec-92  b_null created
  295.  
  296. ******************************************************************************/
  297.  
  298. DEFUSERCMD("unmap", 1, CF_VWM|CF_COK|CF_ICO, void, do_unmap, (void),)
  299. {
  300.     unmapkey ( currenthash(), GetArg(1) );
  301. } /* do_unmap */
  302.  
  303.  
  304.  
  305. /*****************************************************************************
  306.  
  307.     NAME
  308.     do_keysave
  309.  
  310.     PARAMETER
  311.     void
  312.  
  313.     RESULT
  314.     -/-
  315.  
  316.     RETURN
  317.     void
  318.  
  319.     DESCRIPTION
  320.     command interface for keyhashes/savemap
  321.  
  322.     NOTES
  323.     for interface with [X]DME version < 1.70
  324.  
  325.     BUGS
  326.  
  327.     EXAMPLES
  328.  
  329.     SEE ALSO
  330.     do_keyload, keyhashes/savemap
  331.  
  332.     INTERNALS
  333.  
  334.     HISTORY
  335.     14-Dec-92  b_null created
  336.  
  337. ******************************************************************************/
  338.  
  339. static int _keysave (FILE *fi, APTR kt) {
  340.     savekeys (kt, fi);
  341.     return 1;
  342. }
  343.  
  344. DEFUSERCMD("keysave", 1, CF_VWM|CF_ICO, void, do_keysave, (void),)
  345. {
  346.     std_writefile(_keysave, currenthash());
  347. } /* do_keysave */
  348.  
  349.  
  350.  
  351. /*****************************************************************************
  352.  
  353.     NAME
  354.     do_keyload
  355.  
  356.     PARAMETER
  357.     void
  358.  
  359.     RESULT
  360.     -/-
  361.  
  362.     RETURN
  363.     void
  364.  
  365.     DESCRIPTION
  366.     command interface for keyhashes/loadmap
  367.  
  368.     NOTES
  369.     for interface with [X]DME version < 1.70
  370.  
  371.     BUGS
  372.  
  373.     EXAMPLES
  374.  
  375.     SEE ALSO
  376.     do_keysave, keyhashes/loadmap
  377.  
  378.     INTERNALS
  379.  
  380.     HISTORY
  381.     14-Dec-92  b_null created
  382.  
  383. ******************************************************************************/
  384.  
  385. static int _keyload (FILE *fi, APTR kt) {
  386.     int lineno = 0;
  387.     if (av[0][3] != 'm') /* MERGE added */
  388.     dealloc_hash (kt);
  389.     loadkeys (kt, fi, &lineno);
  390.     return 1;
  391. }
  392.  
  393. DEFUSERCMD("keyload", 1, CF_VWM|CF_ICO, void, do_keyload, (void),;)
  394. DEFUSERCMD("keymerge", 1, CF_VWM|CF_ICO, void, do_keyload, (void),)
  395. {
  396.     std_readfile(_keyload, currenthash());
  397. } /* do_keyload */
  398.  
  399.  
  400.  
  401. /*****************************************************************************
  402.  
  403.     NAME
  404.     do_qualifier
  405.  
  406.     PARAMETER
  407.     void
  408.  
  409.     RESULT
  410.     -/-
  411.  
  412.     RETURN
  413.     void
  414.  
  415.     DESCRIPTION
  416.     command interface for keyaddes/qualifier
  417.  
  418.     NOTES
  419.     for interface with [X]DME version > 1.70
  420.  
  421.     BUGS
  422.  
  423.     EXAMPLES
  424.  
  425.     SEE ALSO
  426.     keyhashes/qualifier
  427.  
  428.     INTERNALS
  429.  
  430.     HISTORY
  431.     16 Dec 1992 b_null created
  432.  
  433. ******************************************************************************/
  434.  
  435. DEFUSERCMD("qualifier", 1, CF_VWM|CF_ICO|CF_COK, void, do_qualifier, (void),)
  436. {
  437.     qualifier (GetArg(1));
  438. } /* do_qualifier */
  439.  
  440.  
  441. DEFVARTREE( 91, "KEY_", VAR_MAP, 4, 4, VF_COP, NULL, NULL, mapkey, keyspectomacro )
  442. Prototype char*keyspectomacro(char*);
  443. char * keyspectomacro (char * str)
  444. {
  445.     return (keyspec2macro(currenthash(), str));
  446. } /* keyspectomacro */
  447.  
  448.  
  449.  
  450. /*****************************************************************************
  451.  
  452.     NAME
  453.     do_new_keytable
  454.  
  455.     PARAMETER
  456.     void
  457.  
  458.     RESULT
  459.     -/-
  460.  
  461.     RETURN
  462.     void
  463.  
  464.     DESCRIPTION
  465.     command interface for keyaddes/qualifier
  466.  
  467.     NOTES
  468.     <never tested>
  469.  
  470.     BUGS
  471.     <none known>
  472.  
  473.     EXAMPLES
  474.  
  475.     SEE ALSO
  476.  
  477.     INTERNALS
  478.  
  479.     HISTORY
  480.     28 Jan 1993  b_null created
  481.  
  482. ******************************************************************************/
  483.  
  484. DEFUSERCMD("newkeytable", 1, CF_VWM|CF_ICO|CF_COK, void, do_new_keytable, (void),)
  485. {
  486.     Ep->keytable = new_keytable (GetArg(1), 1);
  487. } /* do_new_keytable */
  488.  
  489.  
  490.  
  491. /*****************************************************************************
  492.  
  493.     NAME
  494.     do_del_keytable
  495.  
  496.     PARAMETER
  497.     void
  498.  
  499.     RESULT
  500.     -/-
  501.  
  502.     RETURN
  503.     void
  504.  
  505.     DESCRIPTION
  506.     command interface for keyaddes/qualifier
  507.  
  508.     NOTES
  509.     <never tested>
  510.  
  511.     BUGS
  512.     <none known>
  513.  
  514.     EXAMPLES
  515.  
  516.     SEE ALSO
  517.  
  518.     INTERNALS
  519.  
  520.     HISTORY
  521.     28 Jan 1993  b_null created
  522.  
  523. ******************************************************************************/
  524.  
  525. DEFUSERCMD("remkeytable", 0, CF_VWM|CF_ICO|CF_COK, void, do_del_keytable, (void),)
  526. {
  527.     KEYTABLE * kt = currenthash ();
  528.     ED         * ep;
  529.  
  530.     for (ep = GetHead (&DBase); ep; ep = GetSucc (ep)) {
  531.     if (ep->keytable == kt) {
  532.         ep->keytable = NULL;
  533.     } /* if */
  534.     } /* for */
  535.  
  536.     delete_keytable (kt, 0);
  537. } /* do_del_keytable */
  538.  
  539.  
  540.  
  541. /*****************************************************************************
  542.  
  543.     NAME
  544.     do_use_keytable
  545.  
  546.     PARAMETER
  547.     void
  548.  
  549.     RESULT
  550.     -/-
  551.  
  552.     RETURN
  553.     void
  554.  
  555.     DESCRIPTION
  556.     command interface for keyaddes/qualifier
  557.  
  558.     NOTES
  559.     <never tested>
  560.  
  561.     BUGS
  562.     <none known>
  563.  
  564.     EXAMPLES
  565.  
  566.     SEE ALSO
  567.  
  568.     INTERNALS
  569.  
  570.     HISTORY
  571.     28 Jan 1993  b_null created
  572.  
  573. ******************************************************************************/
  574.  
  575. DEFUSERCMD("usekeytable", 1, CF_VWM|CF_ICO|CF_COK, void, do_use_keytable, (void),)
  576. {
  577.     KEYTABLE * kt = get_keytable (GetArg (1));
  578.  
  579.     if (kt) {
  580.     Ep->keytable = kt;
  581.     } /* if */
  582. } /* do_use_keytable */
  583.  
  584.  
  585.  
  586. /*****************************************************************************
  587.  
  588.     NAME
  589.     currenthash
  590.  
  591.     PARAMETER
  592.     void;
  593.  
  594.     RESULT
  595.     the current keytable
  596.  
  597.     RETURN
  598.     void;
  599.  
  600.     DESCRIPTION
  601.     An interface to the current ED's window
  602.  
  603.     NOTES
  604.     This function could easiliy be replaced by a macro
  605.  
  606.     HISTORY
  607.     26-08-93    b_noll  created
  608.  
  609. ******************************************************************************/
  610.  
  611. Prototype void *currenthash (void);
  612. void *currenthash(void)
  613. {
  614.     /* return(onlyhash); */
  615.  
  616.     if ((Ep == NULL) || (Ep->keytable == NULL)) {
  617.     return (get_keytable (NULL));
  618.     } /* if */
  619.     return (Ep->keytable);
  620. } /* currenthash */
  621.  
  622. /*****************************************************************************
  623.  
  624.     NAME
  625.     keyfind
  626.     keygethelp
  627.     keysethelp
  628.     keygetcommand
  629.     keysetcommand
  630.     keycall
  631.  
  632.     PARAMETER
  633.  
  634.     RESULT
  635.  
  636.     RETURN
  637.  
  638.     DESCRIPTION
  639.     interfaces to support handles used by the
  640.     STATIC Command Interface
  641.     in order to enable use of COMTREE key
  642.     as well as VARTREE keycomm/keyhelp
  643.  
  644.     NOTES
  645.     <never tested>
  646.  
  647.     BUGS
  648.     <none known>
  649.  
  650.     EXAMPLES
  651.  
  652.     SEE ALSO
  653.  
  654.     INTERNALS
  655.  
  656.     HISTORY
  657.     05-08-94 null created
  658.  
  659. ******************************************************************************/
  660.  
  661. #ifdef STATIC_COM
  662.  
  663.  Prototype APTR keyfind (char *name);
  664. APTR keyfind (char *name) {
  665.     return findhash(currenthash(), name, NULL, NULL);
  666. } /* keyfind */
  667.  
  668.  Prototype char *keygethelp(APTR handle);
  669. char *keygethelp(APTR handle) {
  670.     return ((HASH *)handle)->help;
  671. } /* keygethelp */
  672.  
  673.  Prototype char *keygetcommand(APTR handle);
  674. char *keygetcommand(APTR handle) {
  675.     return ((HASH *)handle)->com;
  676. } /* keygetcommand */
  677.  
  678.  Prototype char *keysetcommand(APTR handle, char *val);
  679. char *keysetcommand(APTR handle, char *val) {
  680.     char *ptr;
  681.     if (ptr = DupFunc(val)) {
  682.     DeallocFunc(((HASH *)handle)->com);
  683.     ((HASH *)handle)->com = ptr;
  684.     return TRUE;
  685.     } /* if */
  686.     nomemory();
  687.     return FALSE;
  688. } /* keysetcommand */
  689.  
  690.  Prototype char *keysethelp (APTR handle, char *val);
  691. char *keysethelp (APTR handle, char *val) {
  692.     char *ptr;
  693.     if (ptr = DupFunc(val)) {
  694.     DeallocFunc(((HASH *)handle)->help);
  695.     ((HASH *)handle)->help = ptr;
  696.     return TRUE;
  697.     } /* if */
  698.     nomemory();
  699.     return FALSE;
  700. } /* keysethelp */
  701.  
  702.  Prototype int keycall (APTR handle);
  703. int keycall (APTR handle) {
  704.     char *ptr;
  705.     if (ptr = strdup(keygetcommand(handle))) {
  706.     retval = do_command(ptr);
  707.     free (ptr);
  708.     return OK;
  709.     } /* if */
  710.     nomemory();
  711.     return FALSE;
  712. } /* keycall */
  713.  
  714. #endif /* STATIC_COM */
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721. /******************************************************************************
  722. *****  ENDE keycom.c
  723. ******************************************************************************/
  724.